home *** CD-ROM | disk | FTP | other *** search
- //
- // Fichero: EJEMPLOS.CPP
- //
- // Versi≤n: 1.0
- // Autor: Antonio M. EstΘvez Lorenzo
- // Prop≤sito: Muestra los ejemplos de superficies
- // contenidos en el fichero FUNCWIN.SUP
- //
-
- #include <windows.h>
- #include <owl.h>
- #pragma hdrstop
-
- #include "Ejemplos.h"
- #include "Child.h"
- #include "strings.h"
- #include "Errores.ids"
- #include "Ayuda.ids"
-
- typedef struct
- {
- FuncStr Nombre,EcuX,EcuY,EcuZ;
- FuncStr IntvA,IntvB,Escala,Origen;
- FuncStr AngIni;
- FuncStr Nodos;
- } TEjemplo;
-
- struct TDatEjemplo
- {
- TDatEjemplo *Sig,*Ant;
- TEjemplo Datos;
- };
-
- static char NombreStr[]= "Nombre";
- static char EcuXStr[] = "X";
- static char EcuYStr[] = "Y";
- static char EcuZStr[] = "Z";
- static char IntvAStr[] = "Intv A";
- static char IntvBStr[] = "Intv B";
- static char EscalaStr[]= "Escala";
- static char OrigenStr[]= "Origen";
- static char AngIniStr[]= "Angulo";
- static char NodosStr[] = "Nodos";
- static int MatId[10]= {edFunc,edEcuX,edEcuY,edEcuZ,edInfX,edInfY,
- edCoordX,edCoordY,edCoordZ,edNodosX};
-
- /* ProfileStream */
-
- class ProfileStream: public ifstream
- {
- long Posicion;
- public:
- ProfileStream(char *Nombre) : ifstream(Nombre) {Posicion= 0;};
- BOOL BuscaSeccion(char *Sec);
- void BuscaClave(char *Clave, char *Str, int Long, char *Defect);
- };
-
- BOOL ProfileStream::BuscaSeccion(char *Sec)
- {
- BOOL Encontrado;
- char Seccion[80];
- char Linea[256];
-
- clear();
- seekg(Posicion);
- wsprintf(Seccion,"[%s]",Sec);
- Encontrado= FALSE;
- while(!Encontrado && !bad() && !eof())
- {
- getline(Linea,LongFunc);
- Encontrado= StrEqu(Linea, Seccion);
- }
- if(Encontrado)
- Posicion= tellg();
- return Encontrado;
- }
-
- void ProfileStream::BuscaClave(char *Clave, char *Str, int Long, char *Defect)
- {
- char Linea[256];
- char tmpStr[256];
- BOOL Encontrado= FALSE;
- BOOL Seguir= TRUE;
-
- clear();
- seekg(Posicion);
- do{
- getline(Linea,LongFunc);
- if(Linea[0]== '[')
- Seguir= FALSE;
- else
- {
- StrSep(Linea,tmpStr,'=');
- Encontrado= StrEqu(Linea, Clave);
- }
- }while(Seguir && !Encontrado && !bad() && !eof());
- if(Encontrado)
- StrMov(Str, tmpStr, Long);
- else
- StrMov(Str, Defect, Long);
- }
-
-
- /* TDlgEjemplos */
-
- TDatEjemplo *TDlgEjemplos::Primer;
- TDatEjemplo *TDlgEjemplos::Ultimo;
- TDatEjemplo *TDlgEjemplos::Actual;
-
- TDlgEjemplos::TDlgEjemplos(PTWindowsObject parent, PTModule module)
- :TWindDlg(parent, dgEjemplos, module)
- {
- for(int i= 0; i< sizeof(MatId)/sizeof(MatId[0]); i++)
- new TStatic(this,MatId[i],LongFunc)->EnableTransfer();
- ChildWind= new TChildEjemplo(this);
- DisableTransfer();
- }
-
- void TDlgEjemplos::SetupWindow()
- {
- TWindDlg::SetupWindow();
-
- RECT Rect;
- GetWindowRect(HWindow, &Rect);
- ShowWindow(ChildWind->HWindow, SW_HIDE);
- ChildWind->Move(Rect.left+6, Rect.top+70);
- Muestra(Actual);
- }
-
- BOOL TDlgEjemplos::CanClose()
- {
- ChildWind->Ejemplo= FALSE;
- return ChildWind->CanClose();
- }
-
- BOOL TDlgEjemplos::HayEjemplos(char *ProgDirect)
- {
- char NombProfile[270];
- int Error= SinError;
- HCURSOR Cursor= SetCursor(LoadCursor(NULL, IDC_WAIT));
-
- Actual= Primer = Ultimo= NULL;
- StrUne(NombProfile,ProgDirect,"FUNCWIN.SUP");
- ProfileStream *Profile= new ProfileStream(NombProfile);
- if(Profile && !Profile->bad())
- {
- LeeEjemplos(Profile);
- if(!Actual || Profile->bad())
- Error= ErrorEjemplos2;
- }
- else
- Error= ErrorEjemplos1;
- if(Profile)
- delete Profile;
- SetCursor(Cursor);
- if(Error)
- Mensaje(NULL,Error);
- else
- return TRUE;
- return FALSE;
- }
-
- void TDlgEjemplos::LeeEjemplos(ProfileStream *Profile)
- {
- TDatEjemplo *pEjemplo;
-
- while(!Profile->bad() && Profile->BuscaSeccion("Superf"))
- {
- pEjemplo= new TDatEjemplo;
- if(Primer)
- {
- pEjemplo->Sig= Primer;
- pEjemplo->Ant= Ultimo;
- Primer->Ant= Ultimo->Sig= pEjemplo;
- }
- else
- Actual= Primer= pEjemplo->Sig= pEjemplo->Ant= pEjemplo;
- Ultimo= pEjemplo;
-
- TEjemplo *Datos= &pEjemplo->Datos;
-
- Profile->BuscaClave(NombreStr,Datos->Nombre,LongFunc,"Sin nombre");
- Profile->BuscaClave(EcuXStr, Datos->EcuX, LongFunc,"");
- Profile->BuscaClave(EcuYStr, Datos->EcuY, LongFunc,"");
- Profile->BuscaClave(EcuZStr, Datos->EcuZ, LongFunc,"");
- Profile->BuscaClave(IntvAStr, Datos->IntvA, LongFunc,"-1,1");
- Profile->BuscaClave(IntvBStr, Datos->IntvB, LongFunc,"-1,1");
- Profile->BuscaClave(EscalaStr,Datos->Escala,LongFunc,"10,10,10");
- Profile->BuscaClave(OrigenStr,Datos->Origen,LongFunc,"0,0,0");
- Profile->BuscaClave(AngIniStr,Datos->AngIni,LongFunc,"0,0,0");
- Profile->BuscaClave(NodosStr, Datos->Nodos, LongFunc,"20,20");
- }
- }
-
- void TDlgEjemplos::DibujaEjemplo()
- {
- TDatEcuPar EcuPar;
-
- Convierte(&EcuPar);
- ChildWind->ModifSuperf(&EcuPar);
- SendMessage(ChildWind->HWindow,WM_COMMAND,cmDibujar,NULL);
- }
-
- void TDlgEjemplos::Muestra(TDatEjemplo *Ejemplo)
- {
- Actual= Ejemplo;
- TransferBuffer= &Ejemplo->Datos;
- TransferData(TF_SETDATA);
- if(IsWindowVisible(ChildWind->HWindow))
- DibujaEjemplo();
- }
-
- void TDlgEjemplos::IDSiguiente(RTMessage)
- {
- if(Actual)
- Muestra(Actual->Sig);
- }
-
- void TDlgEjemplos::IDAnterior(RTMessage)
- {
- if(Actual)
- Muestra(Actual->Ant);
- }
-
- void TDlgEjemplos::IDPrimer(RTMessage)
- {
- if(Primer)
- Muestra(Primer);
- }
-
- void TDlgEjemplos::IDUltimo(RTMessage)
- {
- if(Ultimo)
- Muestra(Ultimo);
- }
-
- void TDlgEjemplos::Convierte(TDatEcuPar *EcuPar)
- {
- StrCpy(EcuPar->Nombre, Actual->Datos.Nombre);
- StrCpy(EcuPar->Func.X, Actual->Datos.EcuX);
- StrCpy(EcuPar->Func.Y, Actual->Datos.EcuY);
- StrCpy(EcuPar->Func.Z, Actual->Datos.EcuZ);
-
- SeparaParam(Actual->Datos.IntvA, EcuPar->Param.Intv.X.Inf,
- EcuPar->Param.Intv.X.Sup);
- SeparaParam(Actual->Datos.IntvB, EcuPar->Param.Intv.Y.Inf,
- EcuPar->Param.Intv.Y.Sup);
- SeparaParam(Actual->Datos.Escala, EcuPar->Param.Escala.X,
- EcuPar->Param.Escala.Y,
- EcuPar->Param.Escala.Z);
- SeparaParam(Actual->Datos.Origen, EcuPar->Param.Origen.X,
- EcuPar->Param.Origen.Y,
- EcuPar->Param.Origen.Z);
- SeparaParam(Actual->Datos.AngIni, EcuPar->Param.AngIni.X,
- EcuPar->Param.AngIni.Y,
- EcuPar->Param.AngIni.Z);
- SeparaParam(Actual->Datos.Nodos, EcuPar->Param.Nodos.X,
- EcuPar->Param.Nodos.Y);
- }
-
- void TDlgEjemplos::IDDibujar(RTMessage)
- {
- ShowWindow(ChildWind->HWindow,SW_SHOW);
- DibujaEjemplo();
- }
-
- void TDlgEjemplos::IDCopiar(RTMessage)
- {
- TDatosEcuPar EcuPar;
-
- ChildWind->GetSuperfData(&EcuPar);
- Convierte(&EcuPar.Superf);
- SendMessage(Parent->HWindow,WM_COMMAND,cmCopiaEjemplo,(long)&EcuPar);
- }
-
-